import 'reflect-metadata'

function Prop(): PropertyDecorator {
	return ((target: any, key: string) => {
		const type = Reflect.getMetadata('design:type', target, key)
		const param = Reflect.getMetadata('design:paramtypes', target, key)
		const returntype = Reflect.getMetadata('design:returntype', target, key)

		console.group('prop')
		console.log(`${key} prop type: ${type.name}`)
		console.log(`${key} prop param: ${param}`)
		console.log(`${key} prop return: ${returntype}`)
		console.groupEnd()
	}) as PropertyDecorator
}

function MethodDecorator(): MethodDecorator {
	return ((target, key: string, descriptor) => {
		// 参数
		const type = Reflect.getMetadata('design:type', target, key)
		const param = Reflect.getMetadata('design:paramtypes', target, key)
		const returntype = Reflect.getMetadata('design:returntype', target, key)
		console.group('methods')
		console.log(`${key} methods type: ${type.name}`)
		console.log(`${key} methods param: ${param}`)
		console.log(`${key} methods return: ${returntype}`)
		console.groupEnd()
	}) as MethodDecorator
}

function ClassDeco(): ClassDecorator {
	return ((target) => {
		const type = Reflect.getMetadata('design:type', target)
		const param = Reflect.getMetadata('design:paramtypes', target)
		const returntype = Reflect.getMetadata('design:returntype', target)
		console.group('class')
		console.log(`ClassDeco type: ${type}`)
		console.log(`ClassDeco param: ${param}`)
		console.log(`ClassDeco return: ${returntype}`)
		console.groupEnd()
	}) as ClassDecorator
}

@ClassDeco()
class GetMethods {
	constructor(a: string, b: number) {}

	@Prop()
	prop: string = ''

	@MethodDecorator()
	main(p: string, g: number): string {
		return 'main'
	}
}
